// 材料费汇总页面
import dayjs from 'dayjs'
import { Button } from 'antd'
import { useState } from 'react'
import { useMount } from 'ahooks'

import { WijmoBase } from '../../Router/Wijmo'
import { GetIndexedDB } from '../../Utils/IndexedDB'
import { RedoOutlined, SearchOutlined, ExportOutlined, FileImageOutlined } from '@ant-design/icons';

const wijmoConfig = async () => {
    const options = await GetIndexedDB('options')
    return ({
        get: 'getCaiLiaoYunShuInfo',
        params: {
            statisticstype: 0,
            orgtype: 0,
            pageIndex: 1,
            pageSize: 100000,

        },
        initParameter: {
            group: [],
            sort: [],
            groupPanel: true,
            filter: true,
            addSum: true,
            addIndex: true,
            topText: 'Ω',
            btmText: 'Ψ',
        },
        configuration: {
            allowSorting: 'MultiColumn',
            isReadOnly: true,
            selectionMode: 5,
            allowMerging: "Cells",
        },
        optionsBtn: click => ([
            {
                key: '0',
                type: 'group',
                label: '数据',
                children: [
                    { key: 'refresh', label: <Button type='link' onClick={() => click('onRefresh')} ><RedoOutlined style={{ color: '#13c2c2' }} />刷新数据</Button> },
                    { key: 'search', label: <Button type='link' onClick={() => click('onSearch')} ><SearchOutlined style={{ color: '#13c2c2' }} />条件搜索</Button> },
                ],
            },
            {
                key: '1',
                type: 'group',
                label: '附件',
                children: [
                    {
                        key: '1-1',
                        label: (
                            <Button
                                type='link'
                                onClick={() => click('onAnnexImageList', {
                                    url: 'getYunShuImage',
                                    parameters: [{ file: 'CaiLiaoYunShuUuid', value: 'yS_Gid' }],
                                    success: { file: 'data', url: 'webURL', name: 'imageCategory' }
                                })}
                            >
                                <FileImageOutlined style={{ color: '#13c2c2' }} />
                                查看附件
                            </Button>
                        )
                    },
                ],
            },
            {
                key: '2',
                type: 'group',
                label: '导出',
                children: [
                    { key: '2-1', label: <Button type='link' onClick={() => click('onSaveAct')}><ExportOutlined style={{ color: '#13c2c2' }} />导出选中数据</Button> },
                    { key: '2-2', label: <Button type='link' onClick={() => click('onSaveAll')}><ExportOutlined style={{ color: '#13c2c2' }} />导出全部数据</Button> },
                    { key: '2-3', label: <Button type='link' onClick={() => click('onSaveAdm', { url: 'getCaiLiaoYunShuInfoEXCEL', search: true })}><ExportOutlined style={{ color: '#13c2c2' }} />导出模板数据</Button> },
                ],
            },
        ]),

        columns: [ // 字段设置
            {
                dataIndex: 'yS_Gid',
                valueType: 'Hidden'
            },
            {
                title: '组织机构',
                dataIndex: 'pguid',
                valueType: 'Select',
                valueEnum: options.orgInfo,
                initialValue: options.orgInfo[0].uuid,
                fieldNames: { value: "uuid" },
                hideInTable: true,
            },
            {
                title: '收料开始时间',
                dataIndex: 'begindate',
                valueType: 'DatePicker',
                picker: 'date',
                initialValue: dayjs().add(-2, 'month').format('YYYY-MM-DD'),
                hideInTable: true,
            },
            {
                title: '收料结束时间',
                dataIndex: 'enddate',
                valueType: 'DatePicker',
                picker: 'date',
                initialValue: dayjs().format('YYYY-MM-DD'),
                hideInTable: true,
            },

            {
                title: '费用类型',
                dataIndex: 'feiYongType',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '承运单位',
                dataIndex: 'yS_YunShuFang',
                valueType: 'SelectApi',
                valueJugde: 'pguid',
                valueApi: 'getCiaoLiaoTypeInfoV2',
                valueParams: 'yunShuFang',
                fieldNames: { value: "uuid" },
                width: 240,
                align: 'center',
            },
            {
                title: '车牌号码',
                dataIndex: 'yS_CheHao',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '供应商',
                dataIndex: 'supplierName',
                valueType: 'SelectApi',
                valueJugde: 'pguid',
                valueApi: 'getCiaoLiaoTypeInfoV2',
                valueParams: 'supplierName',
                fieldNames: { value: "uuid" },
                width: 240,
                align: 'center',
            },
            {
                title: '材料名称',
                dataIndex: 'yS_CaiLiaoName',
                valueType: 'SelectApi',
                valueJugde: 'pguid',
                valueApi: 'getCiaoLiaoTypeInfoV2',
                valueParams: 'statisticsName',
                fieldNames: { value: "uuid" },
                width: 240,
                align: 'center',
            },
            {
                title: '收料数量',
                dataIndex: 'yS_YuanShouLiaoShuLiang1',
                valueType: 'Input',
                width: 240,
                align: 'center',
                aggregate: 1,
                aggTitle: '总计',
                smlTitle: '小计'
            },
            {
                title: '收料单位',
                dataIndex: 'yS_Unit',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '转换系数',
                dataIndex: 'ciaoLiaoXiShu',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '收料数量',
                dataIndex: 'yS_ShouLiaoShuLiang',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
                aggregate: 1,
                aggTitle: '总计',
                smlTitle: '小计'
            },
            {
                title: '单价',
                dataIndex: 'yS_Price',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
                aggregate: 3,
                format: 'n2',
                aggTitle: '平均值单价'
            },
            {
                title: '运距（公里）',
                dataIndex: 'yS_HeJiYunJu',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
                aggregate: 1,
                aggTitle: '总计',
                smlTitle: '小计'
            },
            {
                title: '材料单价',
                dataIndex: 'caiLiaoFeiDanJia',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '材料费',
                dataIndex: 'CaiLiaoFeiJinE',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '合计金额',
                dataIndex: 'yS_Money',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
                aggregate: 1,
                aggTitle: '总计',
                smlTitle: '小计'
            },
            {
                title: '发料时间',
                dataIndex: 'yS_FaLiaoDate',
                valueType: 'Date',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '收料时间',
                dataIndex: 'yS_ShouLiaoDate',
                valueType: 'Date',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '发料地',
                dataIndex: 'yS_FaLiaoDi',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '收料地',
                dataIndex: 'yS_ShouLiaoDi',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '发料员',
                dataIndex: 'yS_FaLiaoYuan',
                valueType: 'SelectApi',
                valueJugde: 'pguid',
                valueApi: 'getCiaoLiaoTypeInfoV2',
                valueParams: 'faLiaoYuan',
                fieldNames: { value: "uuid" },
                width: 240,
                align: 'center',
            },
            {
                title: '收料员',
                dataIndex: 'yS_ShouLiaoYuan',
                valueType: 'SelectApi',
                valueJugde: 'pguid',
                valueApi: 'getCiaoLiaoTypeInfoV2',
                valueParams: 'shouLiaoYuan',
                fieldNames: { value: "uuid" },
                width: 240,
                align: 'center',
            },
            {
                title: '数据来源',
                dataIndex: 'yS_ShuJuLeiXing',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
        ],
    })
}



const MaterialTransportationDetails = () => {
    const [WijmoConfig, setWijmoConfig] = useState()
    useMount(async () => {
        setWijmoConfig(await wijmoConfig())
    })

    return (
        <div className='MaterialTransportationDetails'>
            {WijmoConfig && <WijmoBase Config={WijmoConfig} />}
        </div>
    )
}

export default MaterialTransportationDetails